<?php

namespace App\Services;

use App\Interfaces\CategoryInterface;
use Illuminate\Support\Facades\DB;

class CategoryService implements CategoryInterface
{

    public function getAllCategory(int $tenantId): array
    {
        $where = array(
            ['tenantId',$tenantId],
            ['deleted',0]
        );
        $res = DB::table('content_category')->where($where)->orderBy('sortNumber','ASC')->get()->all();
        return $res;
    }

    public function getCategory(int $id)
    {
        $cate = DB::table('content_category')->where('cateId',$id)->where('deleted',0)->get()->first();
        return $cate;
    }

    public function updateCategory(array $data): int
    {
        $where['cateId'] = $data['cateId'];
        $res = DB::table('content_category')->where($where)->update($data);
        return $res;
    }

    public function addCategory(array $data)
    {
        $res = DB::table('content_category')->insertGetId($data);
        return $res;
    }
}
